#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ----------------------------------------------------------
# 主程序
# File path:
# Size:
# Date modified:
# MD5:
# ----------------------------------------------------------
# Author: lmay.Zhou
# Blog: www.lmay.com
# Date: 2017年7月11日 11:42:58
# ----------------------------------------------------------

import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QAction, qApp, QPushButton, QHBoxLayout, QVBoxLayout, \
    QMessageBox

__author__ = "lmay.Zhou";


class MainWindowExample_QWidget(QWidget):
    def __init__(self):
        super().__init__();
        self.initQWidget();

    def initQWidget(self):
        okButton = QPushButton("OK");
        okButton.setToolTip("This is an OK button");
        okButton.clicked.connect(self.onClick);
        cancelButton = QPushButton("Cancel");

        hbox = QHBoxLayout();
        hbox.addStretch(1);
        hbox.addWidget(okButton);
        hbox.addWidget(cancelButton);

        vbox = QVBoxLayout();
        vbox.addStretch();
        vbox.addLayout(hbox);

        self.setLayout(vbox);
        self.setWindowIcon(QIcon("../../resources/favicon.png"));
        self.resize(350, 350);
        self.setWindowTitle('QWidget');
        self.show();

    @pyqtSlot()
    def onClick(self):
        buttonReply = QMessageBox.question(self, 'PyQt5 message', "Do you like PyQt5?",
                                           QMessageBox.Yes | QMessageBox.No);
        if buttonReply == QMessageBox.Yes:
            print('Yes clicked.');
        else:
            print('No clicked.');


class MainWindowExample_QMainWindow(QMainWindow):
    def __init__(self):
        super().__init__();
        self.initQMainWindow();

    def initQMainWindow(self):
        exitAction = QAction(QIcon("../../resources/favicon.jpg"), "&Exit", self);
        exitAction.setShortcut("Ctrl+Q");
        exitAction.setStatusTip("Exit Application");
        exitAction.triggered.connect(qApp.quit);

        helpAction = QAction(QIcon("../../resources/favicon.jpg"), "&Help", self);
        helpAction.setShortcut("Ctrl+H");
        helpAction.setStatusTip("QQ: 379839355");
        helpAction.triggered.connect(qApp.quit);

        aboutAction = QAction(QIcon("../../resources/favicon.png"), "&About", self);
        aboutAction.setShortcut("Ctrl+A");
        aboutAction.setStatusTip("Author: lmay.Zhou");
        aboutAction.triggered.connect(qApp.quit);

        self.statusBar();
        menubar = self.menuBar();
        fileMenu = menubar.addMenu("&File");
        helpMenu = menubar.addMenu("&Help");
        fileMenu.addAction(exitAction);
        helpMenu.addAction(helpAction);
        helpMenu.addAction(aboutAction);

        toolBar = self.addToolBar("Exit");
        toolBar.addAction(exitAction);

        self.setWindowIcon(QIcon("../../resources/favicon.png"));
        self.setGeometry(300, 300, 350, 350);
        self.setWindowTitle("QMainWindow");
        self.show();


if __name__ == "__main__":
    app = QApplication(sys.argv);
    mw = MainWindowExample_QWidget();
    # mw = MainWindowExample_QMainWindow();
    sys.exit(app.exec_());
